﻿using System;
using System.ComponentModel;
using Caliburn.Micro;

namespace NathansMapInfoProjects.PluginManager.Services
{
    public class AsAsnyc : IResult
    {
        private readonly System.Action action;

        public AsAsnyc(System.Action action)
        {
            this.action = action;
        }

        public void Execute(ActionExecutionContext context)
        {
            var backgroundWorker = new BackgroundWorker();
            backgroundWorker.DoWork += (e, sender) => action();
            backgroundWorker.RunWorkerCompleted += (e, sender) => Completed(this, new ResultCompletionEventArgs());
            backgroundWorker.RunWorkerAsync();
        }

        public event EventHandler<ResultCompletionEventArgs> Completed;
    }
}